package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xmy.cultivate.entity.SignOffSatisfaction;
import com.xmy.cultivate.service.ISignOffSatisfactionService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 记录签退满意程度 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2025-08-19
 */
@RestController
@RequestMapping("/api/signOffSatisfaction")
public class SignOffSatisfactionController {

    @Autowired
    ISignOffSatisfactionService iSignOffSatisfactionService;

    @PostMapping("")
    public Result saveSignOffSatisfaction(@RequestBody SignOffSatisfaction signOffSatisfaction ){
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("record_course_id", signOffSatisfaction.getRecordCourseId());
        SignOffSatisfaction satisfaction = iSignOffSatisfactionService.getOne(wrapper);

        if (satisfaction == null) {
            iSignOffSatisfactionService.save(signOffSatisfaction);
        } else {
            satisfaction.setSatisfactionType(signOffSatisfaction.getSatisfactionType());
            iSignOffSatisfactionService.updateById(satisfaction);
        }

        return new Result(Code.OK, "", Code.SAVE_OK_MSG);
    }

}
